<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");


//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["topic_id"], "topic_id", "");
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["show_type"], "show_type", "");
	$g_cgival["show_type"] = intval($g_cgival["show_type"]);
	
	cgi::both($g_cgival["order"], "order", "hot");
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = intval($g_cgival["uid"]);
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["channel"] = "album";
	$g_show["pcount"] = $g_cgival["pcount"] = 20;
	$topic_id = $g_cgival["topic_id"];
	$show_type = $g_cgival["show_type"];
	$order = $g_cgival["order"];
	$uid = $g_cgival["uid"];
	
	$g_show["topic_id"] = $topic_id;
	$g_show["show_type"] = $show_type;
	$g_show["order"] = $order;
	$g_show["uid"] = $uid;
	//登录相关
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		
		$current_uid = $user_detail_info["uid"];
		$current_user_nickname = $user_detail_info["user_nickname"];
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
	}
	else
	{
		/*$url = "/user/login.php?url={$_SERVER["REQUEST_URI"]}";
		header("Location:$url");*/
	}	
	
	
	$page_title = "专辑首页-微博游戏玩家专辑";
	
	
	$db_album_info = new db_album_info();
	$db_user_info = new db_user_info();
	if($order == "time")
	{
		$list = $db_album_info->get_album_index_list_order_by_time($g_cgival["p"],$g_cgival["pcount"],$show_type,$topic_id,$uid);
	
	}
	else
	{
		$list = $db_album_info->get_album_index_list_order_by_hot($g_cgival["p"],$g_cgival["pcount"],$show_type,$topic_id,$uid);
	}
	$count = $db_album_info->get_album_index_count($show_type,$topic_id,$uid);
	
	foreach($list as $key => $value)
	{
		$list[$key]['create_time'] = TimeFormatter::timeFormatShort(strtotime($value['create_time']));
		$list[$key]["pic1"] = str_replace("/bmiddle/","/thumb300/",$list[$key]["pic1"]);
		$list[$key]["pic2"] = str_replace("/bmiddle/","/square/",$list[$key]["pic2"]);
		$list[$key]["pic3"] = str_replace("/bmiddle/","/square/",$list[$key]["pic3"]);
		$list[$key]["pic4"] = str_replace("/bmiddle/","/square/",$list[$key]["pic4"]);
		
	}
	
	
	$g_show["list"] = $list;
	$g_show["count"] = $count;
	
	$g_show["page_keywords"]  = "游戏专辑分享,游戏分享,微博玩家,新浪微博玩家,游戏分类专辑,游戏专辑图片";
	$g_show["page_desc"]  = "分享微博图片专辑,新浪微博玩家发的游戏图片专辑,根据游戏分类推荐专辑";
	$g_show["page_title"] =$page_title;
	
	$Pages = new Pages($count,$g_cgival["p"],$g_cgival["pcount"]);
	$g_show["page_bar"] = $Pages->getLinks("?topic_id={$g_cgival["topic_id"]}&show_type={$g_cgival["show_type"]}&order={$order}&p=",8);
	
	$g_show["topic_id"] = $g_cgival["topic_id"];
	$g_show["topic_show_type"] = $config["topic_show_type"];
	
	
	$daohang[] = "<a href='/album/'>专辑</a>";
	
	if($topic_id)
	{
		
		$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
		$item = $db_mblog_cron_topic_tag->get_mblog_cron_topic_tag_item_by_id($topic_id);
		$g_show["topic_item"] = $item;
		
		if($item["show_type"])$daohang[] = "<a href='/album/?show_type=".$item["show_type"]."'>".$config["topic_show_type"][$item["show_type"]]."</a>";
		$daohang[] = "<a href='/album/?topic_id=".$topic_id."'>".$item["topic"]."</a>";
	}
	elseif($show_type)
	{
		$daohang[] = "<a href='/album/?show_type=".$show_type."'>".$config["topic_show_type"][$show_type]."</a>";
	}
	else
	{
		$daohang[] = "首页";
	}
	
	
	$g_show["daohang"] =join(" <i>&gt;</i> ",$daohang);
	
	//类型1
	$mod_mblog = new mod_mblog();
	list($list1,$list2,$list3,$list4) = $mod_mblog->get_topic_list_order_by_like();
	$g_show["list1"] = $list1;
	$g_show["list2"] = $list2;
	$g_show["list3"] = $list3;
	$g_show["list4"] = $list4;
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("album/huaban_index.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

